package com.lz.ovuola.util.redis.cluster;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;

import redis.clients.jedis.JedisPoolConfig;

/**
 * 
 * @author fz
 *
 */
// @Configuration
public class JedisClusterConnectionFactoryConfig {

	/**
	 * Type safe representation of application.properties
	 */
	// @Autowired
	private RedisProperties redisProperties;
	// @Autowired
	private JedisPoolConfig jedisPoolConfig;

	// @Bean(name = "redisClusterConnectionFactoryConfig")
	public RedisConnectionFactory connectionFactory() {
		// 对密码不支持
		String[] serverArray = redisProperties.getClusterNodes().split(",");
		JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory(
				new RedisClusterConfiguration(Arrays.asList(serverArray)),
				jedisPoolConfig);
		// redisConnectionFactory.setPassword("miyou110011youmi");
		return redisConnectionFactory;
	}
}